package com.zhanggm.springboot.springbootdemo05.controller;

import com.zhanggm.springboot.springbootdemo05.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Executors;

@RestController
public class UserController {

    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    @RequestMapping("es")
    public String es(HttpServletRequest request){
        return "es";
    }
    /**
     * 登陆接口
     * @param request
     * @return
     */
    @RequestMapping("login")
    public boolean login(HttpServletRequest request){
        request.getSession().setAttribute("userInfo","admin");
        return true;
    }

    /**
     * 首页接口
     * @param request
     * @return
     */
    @RequestMapping("index")
    public String index(HttpServletRequest request){
        return "index";
    }

    @RequestMapping("welcome")
    public String welcome(HttpServletRequest request){
        return "welcome";
    }

    @Autowired
    private OrderService orderService;

    @RequestMapping("addOrder")
    public String addOrder(){
        orderService.addOrder();
        return "下单成功";
    }


    @RequestMapping("pay")
    public String pay(){
        orderService.pay();
        //操作非常耗时
        orderService.sendMsg();
        orderService.sendEmail();
        return "支付成功";
    }

}
